package com.launch.carmanager.lanuncher;

import android.content.Context;
import android.support.annotation.StringRes;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;

import com.launch.carmanager.R;
import com.launch.carmanager.common.utils.ResourceUtils;


/**
 * Created by ganquan on 2019/3/29 14:28
 */
public class LauncherAdapter extends FragmentPagerAdapter {

    private final
    @StringRes
    int[] TITLE_IDS;

    private Context context;

    LauncherAdapter(FragmentManager fm, Context context) {
        super(fm);
        this.context = context;
    }

    @Override
    public Fragment getItem(int position) {
        switch (position) {
            case 0:
                return TaskFragment.newInstance();
            case 1:
                return OrderFragment.newInstance();
            case 2:
                return CarsFragment.newInstance();
            case 3:
                return MineFragment.newInstance();
            default:
                return null;
        }
    }

    {
        TITLE_IDS = new int[]{
                R.string.tab_task, R.string.tab_order,R.string.tab_cars,
                R.string.tab_mine,
        };
    }

    @Override
    public int getCount() {
        return TITLE_IDS.length;
    }

    @Override
    public CharSequence getPageTitle(int position) {
        return ResourceUtils.getString(context, TITLE_IDS[position]);
    }

}
